package com.zhanghp.class01;

import com.zhanghp.utils.CommonUtils;

/**
 * @author zhanghp
 * @date 2023/8/7 13:37
 */
public class Code01_PrintBinary {
    public static void printIntBinary(int num) {
        // 一共32位，如果从0算起，是从31开始计算
        for (int i = 31; i >= 0; i--) {
            String binary = (num & (1 << i)) == 0 ? "0" : "1";
            System.out.print(binary + "");
        }
    }

    public static void printLongBinary(long num) {
        // 一共64位，如果从0算起，是从63开始计算
        for (int i = 63; i >= 0; i--) {
            String binary = (num & (1L << i)) == 0 ? "0" : "1";
            System.out.print(binary + "");
        }
    }

    public static void main(String[] args) {
        printIntBinary(4);
        CommonUtils.printDivingLine();
        printLongBinary(4);
        CommonUtils.printDivingLine();
    }
}
